package hoang.hut.libs.adapter;


import hoang.hut.libs.R;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ItemAdapterExtendsBaseAdapter extends BaseAdapter {
	Context mContext;
	LayoutInflater inflater;
	ArrayList<Item> array;
	
	public ItemAdapterExtendsBaseAdapter(Context mContext, ArrayList<Item> array)
	{
		this.mContext = mContext;
		this.array = new ArrayList<Item>();
		this.array = array;
		//this.inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	/*public void notiDB(ArrayList<Object> arrayDB)
	{
		this.array = arrayDB;
		notifyDataSetChanged();
	}*/
	
	
	@Override
	public int getCount() {
		return array.size();
	}

	@Override
	public Object getItem(int position) {
		return array.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ViewHolder holder;

		if (convertView == null) {
			LayoutInflater layoutInflator = LayoutInflater.from(mContext);
			convertView = layoutInflator.inflate(R.layout.layout_item, null);
			holder = new ViewHolder();
			holder.imgThumnail = (ImageView) convertView.findViewById(R.id.imgThumnail);
			holder.tvName = (TextView) convertView.findViewById(R.id.tvName);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}

		Item item = array.get(position);

		holder.imgThumnail.setImageBitmap(item.getPicture());
		holder.tvName.setText(item.getName());

		return convertView;
		
	}
	
	public static class ViewHolder{
		TextView tvName;
		ImageView imgThumnail;
	}

}
